/**
 * 
 */
package kr.co.insoft.publicmesh.controller.comparison.dashboard;

import java.util.HashMap;
import java.util.Map;

import kr.co.insoft.core.service.comparison.dashboard.DashBoardService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author IN-SOFT Inc. Park Jong Taek(jtpark@in-soft.co.kr)
 * 
 */
@Controller
@RequestMapping(value = "comparison/dashboard")
public class DashBoardController {

	final String TILES_PAGE_PREFIX = "tiles/comparison/dashboard";
	final String SINGLE_PAGE_PREFIX = "comparison/dashboard";
	
	@Autowired
	DashBoardService  dashBoardService;

	/**
	 * Comparison Dashboard
	 * 
	 * @param
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "view", method = RequestMethod.GET)
	public String view(
			Model model,
			@RequestParam(value = "ip", defaultValue = "N", required = false) String ip)
			throws Exception {
		if (ip.equals("Y"))
			return SINGLE_PAGE_PREFIX + "/view";

		return TILES_PAGE_PREFIX + "/view";
	}
	
	/**
	 * Comparison Dashboard Chart View
	 * 
	 * @param
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "chart", method = RequestMethod.POST)
	public @ResponseBody Map<String, Object> getChartData(Model model)
			throws Exception {
		Map<String, Object> chartData = new HashMap<String, Object>();
		
		chartData.put("pie", dashBoardService.getPieChartData());
		chartData.put("bar", dashBoardService.getBarChartData());
		
		return chartData;
	}
}
